import type { DomainModel } from '@/apis/model/domain'

export default function useDomainDialog() {
  /**
   * 修改dns服务器地址 dialog
   */
  const editDns = reactive<CommonDialog<{ id: string; dns: [string, string] }>>(
    {
      visible: false,
      record: null,
      loading: false
    }
  )
  const openEditDnsDialog = (domain: DomainModel) => {
    if (domain.assign_ns_list) {
      editDns.record = {
        id: domain.id as unknown as string,
        dns: [
          domain.assign_ns_list[0].id as string,
          domain.assign_ns_list[1].id as string
        ]
      }
    }

    editDns.visible = true
  }

  /**
   * 加入分组 dialog
   */
  const joinGroup = reactive<CommonDialog>({
    visible: false,
    loading: false
  })
  const openJoinGroupDialog = () => {
    joinGroup.visible = true
  }

  return {
    editDns,
    openEditDnsDialog,
    joinGroup,
    openJoinGroupDialog
  }
}
